import api from "@/api";

export function isTokenExpired(token) {
    if (!token) {
        return true;
    }
    const payloadBase64 = token.split('.')[1];
    const decodedJson = atob(payloadBase64);
    const decoded = JSON.parse(decodedJson);
    const exp = decoded.exp;
    const now = Date.now() / 1000; // 当前时间的 UNIX 时间戳（秒）
    return exp < now;
}

// export async function refreshToken() {
//     const refreshToken = localStorage.getItem('refreshToken');
//     try {
//         const response = await api.refreshToken(refreshToken);
//         const newAccessToken = response.data.access;
//         localStorage.setItem('aToken', newAccessToken);
//     } catch (error) {
//         console.error('Error refreshing token:', error);
//         return null;
//     }
// }